#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=3e4+1000;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL dp[maxn][610];
LL a[maxn];
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL n,d;cin>>n>>d;
   for(LL i=1;i<=n;i++){
       LL x;cin>>x;
       a[x]++;
   }
   memset(dp,-0x3f,sizeof(dp));
   dp[d][250]=a[d];
   LL ans=a[d];
   for(LL i=1;i<=30000;i++){
       for(LL j=1;j<=600;j++){
           LL len=j-250+d;
           if(i-len>=0){
              if(len<=0) continue;
              LL mx= max(dp[i-len][j+1],max(dp[i-len][j],dp[i-len][j-1]));
              if(mx!=-0x3f3f3f3f){
                 dp[i][j]=max(dp[i][j],mx+a[i]);
                 ans=max(ans,dp[i][j]);
              }
           }
       }
   }
   cout<<ans<<"\n";
   return 0;
}
